package com.harbintransport.backend.repository;

import com.harbintransport.backend.model.DispatchSuggestion;
import com.harbintransport.backend.model.DispatchSuggestionId;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import java.util.List;

@Repository
public interface DispatchSuggestionRepository extends JpaRepository<DispatchSuggestion, DispatchSuggestionId> {
    List<DispatchSuggestion> findByRouteId(String routeId);

    List<DispatchSuggestion> findByStationId(String stationId);

    List<DispatchSuggestion> findByHour(int hour);

    List<DispatchSuggestion> findByRouteIdAndStationId(String routeId, String stationId);

    List<DispatchSuggestion> findByRouteIdAndHour(String routeId, int hour);

    List<DispatchSuggestion> findByStationIdAndHour(String stationId, int hour);

    List<DispatchSuggestion> findByRouteIdAndStationIdAndHour(String routeId, String stationId, int hour);

    @Query("SELECT DISTINCT d.routeId FROM DispatchSuggestion d ORDER BY d.routeId")
    List<String> findDistinctRouteIds();

    @Query("SELECT DISTINCT d.stationId FROM DispatchSuggestion d WHERE d.routeId = :routeId ORDER BY d.stationId")
    List<String> findDistinctStationIdsByRouteId(@Param("routeId") String routeId);
}